package com.exam.common.Utils;


import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * 发送短信通知类
 */
@Component
public class EmailUtils2 {

    @Value("${email.emailAccount}")
    private  String emailAccount;
    @Value("${email.authCode}")
    private  String authCode;

    public  void sendMsg(String receiver,String title,String msg) throws EmailException {
        HtmlEmail email = new HtmlEmail();
        email.setHostName("smtp.qq.com");
        email.setCharset("utf-8");
        email.addTo(receiver);//设置收件人
        email.setFrom(emailAccount,"考试报名系统官方邮件");//发送人的邮箱为自己的，用户名可以随便填
        email.setAuthentication(emailAccount,authCode);//设置发送人到的邮箱和用户名和授权码(授权码是自己设置的)
        email.setSubject(title);//设置发送主题
        email.setMsg(msg);//设置发送内容
        email.send();//进行发送
    }
}
